import 'dart:io';

import 'package:dart_bean/cass_info.dart';
import 'package:dart_bean/generator.dart';
import 'package:dart_bean/util/ext.dart';

String get genDirName => Generator.config.genDirName;

String get fromJsonParamName => Generator.config.fromJsonParamName;

String get jsonCastParamName => Generator.config.jsonCastParamName;

String get toJsonParamName => Generator.config.toJsonParamName;

int get dartFormatterPageWidth => Generator.config.dartFormatterPageWidth;

String get jsonCastFileName => Generator.config.jsonCastFileName;

String get jsonSupportFileName => Generator.config.jsonSupportFileName;

bool get clickableFileLink => Generator.config.clickableFileLink;

bool get flattenBean => Generator.config.flattenBean;

bool get isStaticFromJson => Generator.config.isStaticFromJson;

bool get autoDefaultValueStyle => Generator.config.autoDefaultValueStyle;

bool get ignoreOfficialBean => Generator.config.ignoreOfficialBean;

String getFromJsonMethodName(CassInfo c) => '_\$${c.name}FromJson';

String getToJsonMethodName(CassInfo c) => '_\$${c.name}ToJson';

String getFromJsonInstanceName(CassInfo c) => 'it';

File getBaseJsonFile(Directory genDir, String fileName) => File('${genDir.path}/base/$fileName'.fixePathStyle());

File getPartFile(Directory libDir, Directory genDir, File dartFile) {
  final path = getRelativePath(dartFile, libDir).replaceFirst('.dart', '.g.dart');
  return File('${genDir.path}/json/$path'.fixePathStyle());
}

///better be private
String getEnumMapName(String enumName) => '_\$${enumName}Map';

///better be private
String getEnumFromJsonName(String enumName) => '_\$${enumName}FromJson';

///should not be '$enumDecodeNullable' maybe conflict to official one
const String decodeEnumName = '\$DecodeEnum';

String printFilePath(File file) {
  if (clickableFileLink) return file.path;
  return getRelativePath(file, Generator.libDir);
}
